home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Add-Ons / After Dark / Joe Judge / Fractal Popcorn ƒ / Popcorn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-09  |  3.5 KB  |  183 lines  |  [TEXT/KAHL]

  1. /*
  2.     Fractal Popcorn - by John Jeppson.
  3.     
  4.     This source code is in the public domain.
  5.     Written in MPW C.
  6.     
  7.     This program is an MPW Tool which implements Clifford A. Pickover's
  8.     "Fractal Popcorn" as described in "Computer Recreations" by
  9.     A.K.Dewdney in Scientific American, July 1989.  
  10.  
  11.     From the MPW Worksheet execute:
  12.     
  13.         Popcorn  top, left, edge
  14.     
  15.     where "top" and "left" are the corner of the target square and "edge"
  16.     is its side.
  17.     
  18.     After the display is drawn you will hear a SysBeep.  You
  19.     may interrupt a partially completed display by clicking the
  20.     mouse or pressing any key. You may not see any immediate
  21.     effect, but the drawing will soon terminate with a double
  22.     SysBeep at the end of the current inner loop.
  23.  
  24.     You may print the completed display by pressing "p".
  25.  
  26.     Return to the shell with the close box.
  27.     
  28.     
  29.     Popcorn -6, -6, 12        - an overall view of the 12 unit square about
  30.                               the origin.
  31.                             
  32.     Popcorn -3, -3, 6         - the central portion of the above. This is about
  33.                               the level of magnification of the illustration
  34.                               in Scientific American.
  35.  
  36.     Popcorn -2.5, -2.5, 2   - enlargements of a single "kernel".
  37.     Popcorn -2,   -2,   1
  38.  
  39. */
  40.  
  41. #if 0 ////////////////
  42. #include <Types.h>
  43. #include <Windows.h>
  44. #include <Memory.h>
  45. #include <Printing.h>
  46. #include <Fonts.h>
  47. #include <Resources.h>
  48. #include <OSUtils.h>
  49. #include <Math.h>
  50. #include <StdLib.h>
  51.  
  52. #endif ///////////////
  53.  
  54. void plot (double x, double y);
  55.  
  56.  
  57. #if 0
  58. void plot (extended x, extended y)
  59. #else
  60. void plot (double x, double y)
  61. #endif
  62. {
  63.     short xi, yi;
  64. #define rint(x)    ((int)x)
  65.     
  66.     xi = rint(x);
  67.     yi = rint(y);
  68.     
  69.     MoveTo (xi, yi);
  70.     Line (0,0);
  71. }
  72.  
  73.  
  74.  
  75. #if 0
  76.  
  77. void makeOffScreen()   /* set up offscreen bitmap to store image */
  78. {
  79.     Size        sizeOfOff;
  80.     short        offRowBytes;
  81.  
  82.     offRowBytes = (((windowEdge - 1) / 16) + 1) * 2;
  83.     sizeOfOff = windowEdge * offRowBytes;
  84.     
  85.     offScreen.baseAddr = (QDPtr) NewPtr(sizeOfOff);
  86.     offScreen.rowBytes = offRowBytes;
  87.     SetRect(&(offScreen.bounds), 0, 0, windowEdge, windowEdge);
  88. }
  89.  
  90.  
  91. void printWindow()
  92. {
  93.     TPPrPort    pport;
  94.     THPrint        hPrint;
  95.     TPrStatus    PrStatus;
  96.     GrafPtr        oldPort;  
  97.     Boolean     notCancelled = true;
  98.     Boolean        drop;
  99.  
  100.     GetPort (&oldPort);
  101.     PrOpen();
  102.  
  103.     SetFractEnable(true);
  104.     SetFScaleDisable(true);
  105.  
  106.     hPrint = (THPrint) NewHandle(sizeof(TPrint));
  107.     if (ResError())
  108.     {
  109.         printf ("Printing Error %d\n", ResError());
  110.         SysBeep(1);
  111.         PrClose();
  112.         return;
  113.     }
  114.     
  115.     drop = PrValidate(hPrint);
  116.     notCancelled = PrJobDialog (hPrint);
  117.         
  118.     if (notCancelled)
  119.     {
  120.         pport = PrOpenDoc(hPrint, nil, nil);
  121.         if ( PrError() == noErr )
  122.         {
  123.             PrOpenPage(pport, nil);
  124.             if (PrError()==noErr)
  125.                 CopyBits (&offScreen, &(pport->gPort.portBits),
  126.                     &(offScreen.bounds), &(offScreen.bounds),
  127.                         srcCopy, nil);
  128.             PrClosePage(pport);
  129.         }
  130.         PrCloseDoc(pport);
  131.     }
  132.     if ( ((**hPrint).prJob.bJDocLoop == bSpoolLoop)
  133.              && (PrError() == noErr) )
  134.         PrPicFile (hPrint, nil, nil, nil, &PrStatus);
  135.         
  136.     SetFractEnable(false);
  137.     SetFScaleDisable(false);
  138.  
  139.     PrClose();
  140.  
  141.     SetPort (oldPort);
  142. }
  143.  
  144.  
  145. void mainLoop()
  146. {
  147.     Boolean            done = false;
  148.     EventRecord        theEvent;
  149.     WindowPtr        whichWindow;
  150.     short            part;
  151.     
  152.     while ( !done )
  153.     {
  154.         if ( GetNextEvent(everyEvent, &theEvent) )
  155.         {
  156.             switch ( theEvent.what )
  157.             {
  158.                 case updateEvt:
  159.                     doUpdate(display);
  160.                     break;
  161.  
  162.                 case mouseDown:
  163.                     part = FindWindow(theEvent.where, &whichWindow);
  164.                     if ( (whichWindow == display) && (part == inGoAway) )
  165.                         done = true;
  166.                     else
  167.                         SysBeep(1);
  168.                     break;
  169.  
  170.                 case keyDown:
  171.                     if ( 'p' == (theEvent.message & charCodeMask) )
  172.                         printWindow();
  173.                     else
  174.                         SysBeep(1);
  175.                     break;
  176.             }
  177.         }
  178.     }
  179. }
  180.  
  181. #endif
  182.  
  183.